﻿@model SYS_ROLE
@using SailHero.Soft.FrameWork.Models;
@{
    ViewBag.Title = "权限设置";
    Layout = "../Shared/_Layout.cshtml";
}
 <script type="text/javascript">

     $(function () {
         $("#save").click(function () {
             var roleID = $("#RoleID").val();
             var subID = "", parentID = "";
             var temp = "";
             $("input:checked").each(function (i) {
                 subID += $(this).val() + ";";
                 parentID += $(this).attr("parentID") + ";";
             });

             //alert("roleID=" + roleID + "---parentID=" + parentID + "---subID=" + subID);
             var msg = "确定要保存？";
             $.messager.confirm("提示信息", msg, function (r) {
                 if (r) {
                     var url = "/Role/AuthorizationSet2";
                     $.post(url, {
                         roleID: roleID
                            , subID: subID
                            , parentID: parentID
                     },
                        function (data) {
                            if (data == "success") {
                                window.location.href = "/Role/Index";
                            }
                            else {
                                $.messager.alert("错误信息", data, "error");
                            }
                        });
                 }
                 else {

                 }
             });
         });
     });
    </script>
<div id="main_zone">
    <table width="99%" style="text-align: left;" border="0" align="center" cellpadding="3"
        cellspacing="1">
        <tr>
            <td width="18%" class="left_title_1">
                角色名称
            </td>
            <td width="82%" style="text-align: center;">
               @Model.ROLENAME
               @Html.HiddenFor(model => model.ROLEID)
            </td>
        </tr>
       @{
           List<SYS_MODEL> modelList = ViewData["modelList"] as List<SYS_MODEL>;
           List<SYS_MODEL> parentModelList = modelList.Where(model=>model.PARENTID=="" || model.PARENTID==null).OrderBy(model=>model.ORDERNUM).ToList();
           List<SYS_MODEL> subModelList;
           int num = 0;
           foreach (SYS_MODEL mod in parentModelList)
           {
               num++;
               subModelList=modelList.Where(model=>model.PARENTID==mod.MODELID).ToList();
               
               if (num % 2 == 1)
               {
               <tr>
                    <td class="left_title_2">
                   @mod.MODELCNAME
                    </td>
                    <td>
                        <div id="divChk">
                           @ViewBag.Helper.CheckBoxList("chkModel", new SelectList(subModelList, "ModelID", "ModelCName", ViewData["PermissionList"]), new { parentID = mod.MODELID })
                        </div>
                    </td>
                </tr>
               }
               else{
                     <tr>
                    <td class="left_title_1">
                   @mod.MODELCNAME
                    </td>
                    <td>
                        <div id="divChk">
                           @ViewBag.Helper.CheckBoxList("chkModel", new SelectList(subModelList, "ModelID", "ModelCName", ViewData["PermissionList"]), new { parentID = mod.MODELID })
                        </div>
                    </td>
                </tr>
               }
           }
           
       }
        <tr>
            <td colspan="2" class="left_title_2" style="text-align: center;">
                <a id="save" class="easyui-linkbutton">保存</a>&nbsp;&nbsp;&nbsp;&nbsp; 
                <a href="/Role/Index" class="easyui-linkbutton">取消</a>
            </td>
        </tr>
    </table>
    </div>

